<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>添加产品</title>
    <link rel="stylesheet" href="__ADMIN_STATICS__/bootstrap/dist/css/bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/animate.css/animate.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/font-awesome/css/font-awesome.min.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/simple-line-icons/css/simple-line-icons.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/bootstrap-editable/css/bootstrap-editable.min.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/app/css/font.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/app/css/app.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/bootstrap-touchspin/jquery.bootstrap-touchspin.min.css" type="text/css" />
    <link rel="stylesheet" href="__ADMIN_STATICS__/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css" type="text/css" />
    <webuploadercss/>
</head>
<body>
<script src="__ADMIN_STATICS__/jquery/jquery.min.js"></script>
<script src="__ADMIN_STATICS__/bootstrap/dist/js/bootstrap.js"></script>
<div class="wrapper-md">
   <div class="panel panel-default">
    <div class="panel-heading">
        <a href="{:U('Admin/Index/welcome')}"><i class="fa fa-home"></i>&nbsp;首页&nbsp;</a>&gt;&nbsp;&nbsp;<a href="{:U('Admin/Goods/index')}">产品列表</a>&nbsp;&gt;&nbsp;&nbsp;添加产品
    </div>
    <div class="table-responsive">
        <form class="form-horizontal" action="{:U('Admin/Goods/add')}" method="post"> 
            <!-- Nav tabs -->
            <ul class="nav nav-tabs text-center" role="tablist">
                <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">基础信息</a></li>
                <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab" style="display: none;" id="content_config">内容</a></li>
                <li role="presentation"><a href="#album" aria-controls="album" role="tab" data-toggle="tab" id="album_config">产品材料</a></li>
            </ul>
            <!-- Tab panes -->
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="home">
                    <input type="hidden" name="id" value="{$data['id']}" />
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">产品名称</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
					<div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">产品代码</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sn" value="{$data['sn']}" >
                        </div>
                    </div>
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label">分类</label>
                        <div class="col-sm-6">
                            <select name="cid" class="form-control"">
                                <volist id="category" name="allCategory">
                                    <option value="{$category.id}" <if condition="$Think.get.cid eq $category['id']">selected</if>>{$category['_name']}</option>
                                </volist>
                            </select>
                        </div>
                    </div>
					<div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">风险评级</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="fengxian"  placeholder="1-5" value="{$data['fengxian']}">
                        </div>
                    </div>
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">规模</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="guimo"  placeholder="300万" value="{$data['guimo']}">
                        </div>
                    </div>
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">业绩比较基准</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="jizhun" value="{$data['jizhun']}">
                        </div>
                    </div>
					<div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">类固收</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="rank1"  placeholder="8.5%@100万(含)~300万" value="{$data['rank1']}">
                        </div>
                    </div>
					<div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">类固收</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="rank2"  placeholder="8.5%@100万(含)~300万" value="{$data['rank2']}">
                        </div>
                    </div>
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">产品期限</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" placeholder="3个月" name="price">
                            <span></span>
                        </div>
                    </div>
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">募集日期-起始</label>
                        <div class="col-sm-6">
                            <input type="text" value="" class="form-control" name="start_time">
                        </div>
                    </div>
					<div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">募集日期-结束</label>
                        <div class="col-sm-6">
                            <input type="text" value="" class="form-control" name="end_time">
                        </div>
                    </div>
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label" for="input-id-1">排序</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sort" value="{$data['sort']}" data-form-un="1470118834084.755">
                        </div>
                    </div>
                    <div id="expand">

                    </div>
                </div>
                <div role="tabpanel" class="tab-pane" id="profile">
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-1 control-label"></label>
                        <div class="col-sm-10">
                            <ueditor name="content" content=""/>
                        </div>
                    </div>  
                </div>
                
                <div role="tabpanel" class="tab-pane" id="album">
                    <if condition="$data['album'] neq null">
                        <div class="line line-dashed b-b line-lg pull-in"></div>
                        <div class="form-group m-b-none m-l-none m-r-none">
                            <label class="col-sm-2 control-label">已上传附件</label>
                            <div class="col-sm-8">
                                <volist name="data['album']" id="v">
                                    <div class="col-sm-6 v-m m-b-xs album_{$v['id']}">
                                        <div class="col-sm-9">
                                             {$v['name']}
                                            <button type="button" onclick="javascript:if(confirm('确定删除附件？'))delete_album(this)" data-id="{$v['id']}" class="btn btn-danger">删除</button>
                                        </div>
                                    </div>
                                </volist>
                            </div>
                        </div>
                    </if>
                    <div class="line line-dashed b-b line-lg pull-in"></div>
                    <div class="form-group m-b-none m-l-none m-r-none">
                        <label class="col-sm-2 control-label">上传附件</label>
                        <div class="col-sm-6 v-m">
                             <!-- 上传组件容器 开始-->
                            <div id="album_upload" class="xb-uploader">
                                <div class="queueList">
                                    <div class="placeholder">
                                        <div class="filePicker"></div>
                                        <p>选择附件</p>
                                    </div>
                                </div>
                                <div class="statusBar" style="display:none;">
                                    <div class="progress">
                                        <span class="text">0%</span>
                                        <span class="percentage"></span>
                                    </div>
                                    <div class="info"></div>
                                    <div class="btns">
                                        <div class="uploadBtn">开始上传</div>
                                    </div>
                                </div>
                                <div class="album_list" style="display: none;">
                                </div>
                            </div>
                            <!-- 上传组件容器 结束-->
                        </div>
                    </div>
                </div>
            </div>
            <div class="line line-dashed b-b line-lg pull-in"></div>
            <div class="col-sm-4 col-sm-offset-2 m-b">
                <button type="submit" class="btn btn-primary">提交</button>
            </div>
        </form>
    </div>
  </div>
</div>
<script src="__ADMIN_STATICS__/webuploader-0.1.5/webuploader.js"></script>
<script src="__ADMIN_STATICS__/webuploader-0.1.5/uploaderSf.js"></script>  
<script src="__ADMIN_STATICS__/bootstrap-touchspin/jquery.bootstrap-touchspin.min.js"></script>  
<script src="__ADMIN_STATICS__/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>  
<script src="__ADMIN_STATICS__/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Q0AWXP9FNzYvVy6zRAGy8sKs7lWzAZO7"></script>
<script type="text/javascript">
var address = $('input[name="address"]').val();
var lng = $("#lng").val();
var lat = $("#lat").val();
if(address == '' || lng == '' || lat == ''){
    var point = new BMap.Point(116.404, 39.915);
}
if(lng != '' && lat != ''){
    var point = new BMap.Point(lng,lat);
}
// 百度地图API功能
var map = new BMap.Map("allmap",{minZoom:10,maxZoom:20});            // 创建Map实例
  // 添加带有定位的导航控件
var navigationControl = new BMap.NavigationControl({
    // 靠左上角位置
    anchor: BMAP_ANCHOR_TOP_LEFT,
    // LARGE类型
    type: BMAP_NAVIGATION_CONTROL_LARGE,
    // 启用显示定位
    enableGeolocation: true
});
map.addControl(navigationControl);
map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放

var marker = new BMap.Marker(point);  // 创建标注
map.addEventListener("click", function(e){
    var point = new BMap.Point(e.point.lng,e.point.lat);
    map.clearOverlays();
    map.addOverlay(new BMap.Marker(point));
    setPoint(point);
});
map.addOverlay(marker);               // 将标注添加到地图中
map.centerAndZoom(point, 20);

function edit(obj){
    // 创建地址解析器实例
    var myGeo = new BMap.Geocoder();
    var param = $('input[name="address"]').val();
    console.log(param);
    myGeo.getPoint(param, function(point){      
          if (point) {      
                map.centerAndZoom(point, 20);
                map.clearOverlays();      
                map.addOverlay(new BMap.Marker(point));
                setPoint(point);      
          }      
      }, "南宁市");
}

function setPoint(point){
    var lng = point.lng;
    var lat = point.lat;
    $('#lng').val(lng);
    $('#lat').val(lat);
}
</script>

<script type="text/javascript">
upload_init('pic',false,'goods');
getExpand();

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
    // 获取已激活选项卡的名称
    var activeTab = $(e.target).attr('aria-controls');
    var multiple = false;
    var type = 'image';
    if (activeTab == "album") {
        multiple = true;
    }
    if (activeTab == 'attachment') {
        type = 'file';
    }
    // 初始化上传组件
    upload_init(activeTab,multiple,type);
});

function upload_init(activeTab,multiple,type){
    if (type == "goods"){
        sizeLimit = 1;
    }else{
        sizeLimit = 50;
    }
     $('#'+activeTab+'_upload').sfUpload({
        url:"/index.php?m=Admin&c=Goods&a=upload&type="+type,
        picker:activeTab+'_upload',
        multiple:multiple,
        sizeLimit:sizeLimit,
        success:function( data ) {
            if(activeTab == 'album'){
                var str = '<input name="album_path[]" type="hidden" value="'+data.path;
                str += '"/><input name="album_name[]" type="hidden" value="'+data.original;
                str += '"/>';
                $('.album_list').append(str);
            }else{
                $("input[name='cover']").val(data.path);
            }
        },
        error:function( err ) {
            console.info( err );    
        }
    });
}

$("input[name='look_count']").TouchSpin({
    min: 0,
    max: 99999999,
    step: 1,
    decimals: 0,
    boostat: 5,
    maxboostedstep: 10,
    postfix: '次'
});

$('#datetimepicker').datetimepicker({
    format: "yyyy-mm-dd",
    autoclose: true,
    todayBtn: true,
    language:  'zh-CN',
    minView: "month",
});

function getExpand(){
    var cid =  $("select[name='cid']").find("option:selected").val();
    $.ajax({
        type : 'post',
        url : "{:U('Admin/Goods/getExpandAjax')}",
        data : {cid:cid},
        dataType : 'json',
        success : function(data){
            if (data.data.content == 1) {
                $('#content_config').show();
            }else{
                $('#content_config').hide();
            }
            if (data.data.seo == 1) {
                $('#seo_config').show();
            }else{
                $('#seo_config').hide();
            }
            if (data.data.attachment == 1) {
                $('#attachment_config').show();
            }else{
                $('#attachment_config').hide();
            }
            if (data.data.album == 1) {
                $('#album_config').show();
            }else{
                $('#album_config').hide();
            }
            if (data.data.address == 1) {
                $('#address_config').show();
            }else{
                $('#address_config').hide();
            }
            $('#expand').html(data.str);
        }
    });
}

function delete_album(obj){
    var id = $(obj).attr('data-id');
    $.ajax({
        url : "{:U('Admin/Goods/delete_album')}",
        type : "post",
        dataType : "json",
        data : {id:id},
        success : function(data){
            if(data.code){
                $('.album_'+id).remove();
            }else{
                alert(data.msg);
            }
        }
    });
}
</script>
</body>
</html>
